home *** CD-ROM | disk | FTP | other *** search
- ---D_INIT.DOC---
-
- Data Allocation Using DB, DW, DD, DQ, and DT
-
- The 86 computer family supports the three fundamental data types BYTE, WORD,
- and DOUBLEWORD. A byte is eight bits, a word is 16 bits (2 bytes), and a
- doubleword is 32 bits (4 bytes). In addition, the 87 floating-point processor
- manipulates 8-byte quantities, which we call Q-words, and 10-byte quantities,
- which we call T-words. The A86 data allocation statement is used to specify the
- bytes, words, doublewords, Q-words, and T-words which your program will use as
- data. The syntax for the data allocation statement is as follows:
-
- (optional var-name) DB (list of values)
- (optional var-name) DW (list of values)
- (optional var-name) DD (list of values)
- (optional var-name) DQ (list of values)
- (optional var-name) DT (list of values)
-
- The variable name, if present, causes that name to be entered into the symbol
- table as a memory variable with type BYTE (for DB), WORD (for DW), DWORD (for
- DD), QWORD (for DQ), or TWORD (for DT). The variable name should NOT have a
- colon after it, unless you wish the name to be a label (instructions referring
- to it will interpret the label as the constant pointer to the memory location,
- not its contents).
-
- The DB statement is used to reserve bytes of storage; DW is used to reserve
- words. The list of values to the right of the DB or DW serves two purposes. It
- specifies how many bytes or words are allocated by the statement, as well as
- what their initial values should be. The list of values may contain a single
- value or more than one, separated by commas. The list can even be missing;
- meaning that we wish to define a byte or word variable at the same location as
- the next variable.
-
- If the data initialization is in the DATA segment, the values given are ignored,
- except as place-markers to reserve the appropriate number of units of storage.
- The use of "?", which is a synonym for zero, is recommended in this context to
- emphasize the lack of actual memory initialization.
-
- A special value which can be used in data initializations is the DUP construct,
- which allows the allocation and/or initialization of blocks of data. The
- expression n DUP (x) is equivalent to a list with x repeated n times. "x" can
- be either a single value, a list of values, or another DUP construct nested
- inside the first one.
-
- Here are some examples of data initialization statements, with and without DUP
- constructs:
-
- CODE SEGMENT
- DW 5 ; allocate one word, initialized to 5
- DB 0,3,0 ; allocate three bytes, initialized to 0,3,0
- DB 5 DUP (0) ; equivalent to DB 0,0,0,0,0
- DW 2 DUP (0,4 DUP (7)) ; equivalent to DW 0,7,7,7,7,0,7,7,7,7
-
- DATA SEGMENT
- XX DW ? ; define a word variable XX
- YYLOW DB ; no init value: YYLOW is the low byte of word variable YY
- YY DW ?
- X_ARRAY DB 100 DUP (?) ; X_ARRAY is a 100-byte array
- D_REAL DQ ? ; double-precision floating variable
- EX_REAL DT ? ; extended precision floating variable
-
- A character string value may be used to initialize consecutive bytes in a DB
- statement. Each character will be represented by its ASCII code. The
- characters are stored in the order that they appear in the string, with the
- first character assigned to the lowest-addressed byte. In the DB statement that
- follows, five bytes are initialized with the ASCII representation of the
- characters in the string 'HELLO':
-
- DB 'HELLO'
-
- Note that the DB directive is the only place in your program that strings of
- length greater than 2 may occur. In all other contexts (including DW), a string
- is treated as the constant number represent the ASCII value of the string; for
- example, CMP AL,'#' is the instruction comparing the AL-register with the ASCII
- value of the pound-sign. Note further that 2-character string constants, like
- all constants in the 8086, have their bytes reversed. Thus, while DB 'AB' will
- produce hex 41 followed by hex 42, the similar-looking DW 'AB' reverses the
- bytes: hex 42 followed by hex 41.
-
- The DD directive is used to initialize 32-bit doubleword pointers to loactions
- in arbitrary segments of the 86's memory space. Values for such pointers
- are given by two numbers separated by a colon. The segment register value
- appears to the left of the colon; and the offset appears to the right of the
- colon. In keeping with the reversed-bytes nature of memory storage in the 86
- family, the offset comes forst in memory. For example, the statement
-
- DD 01234:05678
-
- appearing in a CODE segment will cause the hex bytes 78 56 34 12 to be
- generated, which is a long pointer to segment 01234, offset 05678.
-